import { fileURLToPath, URL } from 'node:url';
import vue from '@vitejs/plugin-vue';
import { visualizer } from "rollup-plugin-visualizer";
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
const getPath = (path)=>{
    //path 需要获取的文件的路径，（相对于当前文件）
    //import.meta.url当前文件的路径
    let outPath = fileURLToPath(new URL(path, import.meta.url));
    return outPath;
}
export default {
    plugins: [
        vue(),

        /*打包分析*/
        visualizer({
            gzipSize: true,
            brotliSize: true,
            emitFile: false,
            filename: "preview.html", //分析图生成的文件名
            open:false //如果存在本地服务端口，将在打包后自动展示
        }),
        // 帮助解析模块路径
        resolve(),
        // 处理非 ESM 依赖
        commonjs(),
    ],
    build:{//https://cn.vitejs.dev/guide/build.html#library-mode
        lib: {
           entry: getPath('./src/views/modules/preview/components/js/lib.js'),
           name: 'screen-front',
           // 输出的包文件名*!/
           fileName: (format) => {
                return `jpaas-screen-front.${format}.js`;
           }
        },
        rollupOptions: {
            // 确保外部化处理那些你不想打包进库的依赖
            external: ['vue',
                '@lowcode/jpaas-base-lib',
                '@lowcode/jpaas-share-component',
                'echarts'
            ],
            output: {
                // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
                globals: {
                    vue: 'Vue',
                    '@lowcode/jpaas-base-lib':'jpaas-base-lib',
                    '@lowcode/jpaas-share-component':'jpaas-share-component',
                    'echarts':'echarts'
                },
            },
        },
        outDir:'lib',
        assetsDir:'static',
    }
}
